<template>
  <div>
    <a-card :bordered="false" style="position: relative; margin-bottom: 10px">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper" style="position: relative">
        <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol" @keyup.enter.native="onQuery">
          <div class="mode_item">
            <a-form-model-item label="情报事件名称">
              <a-input v-model="formData.incidentName" placeholder="请输入" />
            </a-form-model-item>
            <a-form-model-item label="情报事件编号">
              <a-input v-model="formData.incidentCode" placeholder="请输入" />
            </a-form-model-item>
            <a-form-model-item label="情报任务名称">
              <a-input v-model="formData.taskName" placeholder="请输入" />
            </a-form-model-item>
            <a-form-model-item label="情报任务编号">
              <a-input v-model="formData.taskCode" placeholder="请输入" />
            </a-form-model-item>
          </div>
          <div class="mode_item">
            <a-form-model-item label="情报模型">
              <a-select style="width:100%" v-model="formData.modelId" placeholder="请选择">
                <template v-for="(item, key) in modelList">
                  <a-select-option :key="key" :value="item.id">
                    {{ item.name }}
                  </a-select-option>
                </template>
              </a-select>
            </a-form-model-item>
            <a-form-model-item label="情报状态">
              <a-select v-model="formData.status" placeholder="请选择">
                <a-select-option value="0">全部</a-select-option>
                <a-select-option value="1">未研判</a-select-option>
                <a-select-option value="2">已研判</a-select-option>
              </a-select>
            </a-form-model-item>
            <a-form-model-item label="号码归属地">
              <a-input v-model="formData.phoneArea" placeholder="请输入" />
              <!-- <a-select v-model="formData.phoneArea" placeholder="请选择">
                <a-select-option value="0">全部</a-select-option>
                <a-select-option value="1">海口</a-select-option>
                <a-select-option value="2">三亚</a-select-option>
              </a-select> -->
            </a-form-model-item>
          </div>
          <div class="mode_item mode_item_none">
            <a-form-model-item label="更新时间" class="zdy-form-item-label">
              <a-radio-group buttonStyle="solid" v-model="formData.timeType">
                <a-radio-button v-for="(item, key) in options" :key="key" :value="item.value">
                  {{ item.text }}
                </a-radio-button>
              </a-radio-group>
              <a-range-picker
                v-if="formData.timeType === '0'"
                :allowClear="true"
                v-model="rangePickerTime"
                valueFormat="YYYY-MM-DD"
                @change="rangePickerChange"
                style="margin-left: 10px"
              />
            </a-form-model-item>
          </div>
          <div style="margin-top: 20px">
            <a-form-model-item :wrapper-col="{ offset: 0 }" style="margin-bottom: 0">
              <a-button class="Indormation-list-CX" type="primary" @click="onQuery"> 查询 </a-button>
              <a-button class="Indormation-list-CX" style="margin-left: 10px" @click="onResetForm"> 重置 </a-button>
            </a-form-model-item>
          </div>
        </a-form-model>
      </div>
    </a-card>
    <a-card :bordered="false">
      <!-- 操作按钮区域 -->
      <div style="margin-bottom: 20px">
        <a-button type="primary" :disabled="isDisabled" @click="onAdd()">发起案事件</a-button>
      </div>
      <!-- 表格展示 -->
      <div class="table-page-content">
        <custom-table
          ref="table"
          rowKey="id"
          :showColSettings="true"
          :hideColSettings="['action']"
          :showAlert="false"
          :showSelection="true"
          :loading="loading"
          :columns="columns"
          :dataSource="pageData"
          @selectedRow="onSelectedRow"
          @change="onTableChange"
        >
          <template v-slot:colSettings>
            <a-button class="table-custom-cols"> 字段配置 </a-button>
          </template>
          <template slot="status" slot-scope="text">
            <span class="text_color_1" v-if="text == '0'">待开始</span>
            <span class="text_color_3" v-if="text == '1'">未研判</span>
            <span class="text_color_2" v-if="text == '2'">已研判</span>
          </template>
          <template slot="phone" slot-scope="text, record">
            <!-- {{ record.isSamplePerson }} -->
            <span>{{ text }}</span>
            <a-tag v-if="record.isSamplePerson" style="margin-top:10px;" color="red">负样本人员</a-tag>
          </template>
          <!-- <template slot="updateTime" slot-scope="text, record">
            <span>{{ record.startTime }} -- {{ record.endTime }}</span>
          </template> -->
          <!--操作-->
          <template slot="action" slot-scope="text, record">
            <a-button @click="onYP(record)" type="link" style="padding: 0;">初步研判</a-button>
          </template>
        </custom-table>
      </div>
      <!--页面来源pageType， 1：案事件管理 2：任务情报列表 3： 配置情报列表 4： 重点人列表 5：任务情报管理 6：种子号码列表 7：协查函列表、8 审批列表   10 负样本人员库 11 时空碰撞 -->
      <AddCaseModal
        ref="addCaseModalId"
        title="新增案事件"
        :pageType="2"
        moduleType="intelligence"
        :targetData="selectRows"
        @close="addCaseClose"
        @createSuccess="createSuccess"
      />
      <YpModal ref="ypModalId" />
    </a-card>
  </div>
</template>

<script>
import moment from 'moment'
import * as api from '@/api/wxSmuggle/intelligence.js'
import * as caseApi from '@/api/wxSmuggle/caseEvent.js'
import { querySimpleByPhoneList } from '@/utils/util'
import CustomTable from '@/components/zxd/Table/CustomTable'
import AddCaseModal from '@/views/wxSmuggle/modules/AddCaseModal'
import YpModal from './components/YpModal'
export default {
  components: {
    CustomTable,
    AddCaseModal,
    YpModal
  },
  data() {
    return {
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
      rangePickerTime: [],
      loading: false,
      visible: false,
      reloading: false,
      formData: {},
      isDisabled: true,
      options: [
        { value: '2', text: '今天' },
        { value: '3', text: '近三天' },
        { value: '4', text: '近七天' },
        { value: '0', text: '自定义' }
      ],
      columns: [
        {
          title: '序号',
          dataIndex: 'order',
          scopedSlots: { customRender: 'order' },
          align: 'center',
          width: 60,
          customRender: (text, record, index) =>
            `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
        },
        {
          title: '情报号码',
          dataIndex: 'phone',
          align: 'center',
          scopedSlots: { customRender: 'phone' }
        },
        {
          title: '号码归属地',
          dataIndex: 'phoneArea',
          align: 'center',
          scopedSlots: { customRender: 'phoneArea' }
        },
        {
          title: '情报任务编号',
          dataIndex: 'taskCode',
          align: 'center',
          scopedSlots: { customRender: 'taskCode' }
        },
        {
          title: '情报任务名称',
          dataIndex: 'taskName',
          align: 'center',
          scopedSlots: { customRender: 'taskName' }
        },
        {
          title: '情报事件编号',
          dataIndex: 'incidentCode',
          align: 'center',
          scopedSlots: { customRender: 'incidentCode' }
        },
        {
          title: '情报事件名称',
          dataIndex: 'incidentName',
          align: 'center',
          scopedSlots: { customRender: 'incidentName' }
        },
        {
          title: '模型名称',
          dataIndex: 'modelName',
          align: 'center',
          scopedSlots: { customRender: 'modelName' }
        },
        {
          title: '情报状态',
          dataIndex: 'status',
          width: 80,
          align: 'center',
          scopedSlots: { customRender: 'status' }
        },
        {
          title: '更新时间',
          dataIndex: 'updateTime',
          width: 140,
          align: 'center'
        },
        {
          title: '操作',
          width: 100,
          align: 'center',
          dataIndex: 'action',
          // slots: { title: 'customIsAction' },
          scopedSlots: { customRender: 'action' }
        }
      ],
      pageFilter: {
        pageNo: 1,
        pageSize: 10,
        category: 2 //1案事件，2明文情报
      },
      pageData: [],
      selectRows: [],
      modelList: [],
      infoObject: this.$route.query.infoObject
    }
  },
  created() {
    //从模型带过来的信息,填上并搜索
    if (this.infoObject != undefined) {
      this.formData = Object.assign({}, this.infoObject)
    }
    this.getModalList()
    this.refreshTable()
  },
  methods: {
    moment,
    onSelectedRow(rows) {
      console.log('rows')
      console.log(rows)
      this.selectRows = rows
      this.isDisabled = rows.length > 0 ? false : true
    },
    onQuery() {
      this.pageFilter.pageNo = 1
      this.refreshTable()
    },
    onResetForm() {
      this.formData = {}
      this.pageFilter.pageNo = 1
      this.pageFilter.pageSize = 10
      this.rangePickerTime = []
      this.$nextTick(() => {
        // 重置行政区划
        // this.$refs.linkage.reload()
        this.reload()
      })
      this.refreshTable()
    },
    onTableChange(pagination, pageFilter, sorter) {
      let keyMap = { currentPage: 'pageNo' }
      let paginations = Object.keys(pagination).reduce((newData, key) => {
        let newKey = keyMap[key] || key
        newData[newKey] = pagination[key]
        return newData
      }, {})
      this.pageFilter = Object.assign({}, this.pageFilter, paginations)
      this.refreshTable()
    },
    refreshTable() {
      let formData = Object.assign({}, this.formData, this.pageFilter)
      this.loading = true
      api
        .intelligenceList(formData)
        .then(res => {
          if (res.success) {
            this.pageData = res.result
            this.loading = false
            //判断是否是负样本号码，并添加负样本标签(电话号码字段：phoneNumber传1，phone传2，msisdn传3)
            querySimpleByPhoneList(this, 2, this.pageData.records)
          } else {
            this.loading = false
          }
        })
        .catch(e => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },
    onAdd() {
      // console.log(this.selectRows)
      this.$refs.addCaseModalId.show()
    },
    createSuccess() {
      this.$refs.table.onClearRowKeys()
      this.onQuery()
    },
    addCaseClose() {
      this.$refs.table.onClearRowKeys()
    },
    // 详情
    onYP(record) {
      this.$refs.ypModalId.show(record)
    },
    // 预警时间
    rangePickerChange(date) {
      this.$set(this.formData, 'startTime', date[0])
      this.$set(this.formData, 'endTime', date[1])
    },
    getModalList() {
      caseApi
        .modelList({ category: 2 }) //1案事件，2明文情报
        .then(res => {
          if (res.success) {
            this.modelList = res.result
          }
        })
        .catch(e => {
          this.$message.warn('请求失败！')
        })
    },
    /** 重新加载组件 */
    reload() {
      this.reloading = true
      this.$nextTick(() => (this.reloading = false))
    }
  }
}
</script>
<style lang="less" scoped>
.mode_item {
  display: flex;
  border-bottom: 1px #dadada dashed;
  > div {
    flex: 0 0 25%;
  }
  & > * {
    width: 100%;
    margin-bottom: 0;
    padding: 5px 0;
  }
  &.mode_item_none {
    > div {
      flex: inherit;
    }
  }
  .zdy-form-item-label {
    /deep/.ant-form-item-label {
      width: 70px;
    }
    &.xzqh-form-item-label {
      /deep/.ant-form-item-control-wrapper {
        .ant-form-item-children {
          display: -webkit-box;
        }
      }
      /deep/.area-select {
        // margin-top: 4px;
        line-height: 1;
      }
      /deep/.select-tag {
        width: 162px !important;
        margin-left: 10px;
        margin-top: 3px;
      }
      // /deep/.area-select .area-selected-trigger {
      //   line-height: 1.15;
      // }
      // /deep/.ant-select-lg .ant-select-selection--single{
      //   height: 34px;
      // }
      // /deep/.ant-select-lg .ant-select-selection__rendered {
      //   line-height: 34px;
      //   font-size: 14px;
      // }
    }
  }
}
.search-wrapper-btn {
  position: absolute;
  right: 0;
  top: 15px;
  z-index: 1;
}
/deep/.table-custom-cols {
  top: -48px !important;
}
.custom-ewm {
  padding: 14px;
  background-color: #fff;
  border: 1px #ccc solid;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
}
/deep/.ant-dropdown-menu-item {
  text-align: center;
  border-bottom: 1px #f5f5f5 solid;
  &:last-child {
    border-bottom: 0;
  }
}
/deep/.anticon.anticon-down {
  font-size: 14px !important;
}

.table-page-content {
  /deep/.ant-table-thead > tr > th,
  /deep/.ant-table-tbody > tr > td {
    padding-left: 0;
    padding-right: 0;
  }
  /deep/.ant-table-thead > tr:first-child > th:first-child,
  /deep/.ant-table-tbody > tr > td:first-child {
    padding-left: 10px;
  }
  .text_color_1 {
    color: #f59a23;
    padding-right: 6px;
  }
  .text_color_2 {
    color: #71b604;
    padding-right: 6px;
  }
  .text_color_3 {
    color: #d9001b;
    padding-right: 6px;
  }
}
</style>
